#include "ShapeRectangle.h"

CShapeRectangle::CShapeRectangle(void)
{
	m_name = "Rectangle";
	m_width=0;
	m_height=0;

	m_bKinematic=false;

	//indicate the type of shape
	m_typeOfShape = eRectangleShape;

	//the frictions
	m_dynamicFriction=0.5;
	m_staticFriction=0.5;

	//collision ratio
	m_collisionRatio=1;

	//mass of the object
	m_mass=1;

	//moment of inertia of the object.
	m_inertia=1;

	//position
	m_position= CVector2f(0, 0);
	m_orientation = 0;

	//m_state
	m_collision= false;
	m_resting = false;

	//speed
	m_acceleration = CVector2f(0, 0);
	m_speed = CVector2f(0, 0);
	m_initialSpeed = CVector2f(0, 0);

	m_obb[0] = CVector2f(0, 0);
	m_obb[1] = CVector2f(0, 0);
	m_obb[2] = CVector2f(0, 0);
	m_obb[3] = CVector2f(0, 0);

	m_initialPosition = CVector2f(0, 0);
	m_initialOrientation = 0;

	//collision point
	CVector2f m_collisionPoint = CVector2f(0, 0);
}

CShapeRectangle::~CShapeRectangle(void)
{
}

void CShapeRectangle::calculateBoundingBox()
{
	m_boundingBox[0]= CVector2f((float)-m_width/2, (float)m_height/2);
	m_boundingBox[1]= CVector2f((float)m_width/2, (float)m_height/2);
	m_boundingBox[2]= CVector2f((float)m_width/2, (float)-m_height/2);
	m_boundingBox[3]= CVector2f((float)-m_width/2, (float)-m_height/2);
}

CVector2f* CShapeRectangle::getOrientedBoundingBox()
{
	for(int i=0; i<4; i++)
	{
		//rotation
		float x = cos(m_orientation)*m_boundingBox[i].x - sin(m_orientation)*m_boundingBox[i].y;
		float y = cos(m_orientation)*m_boundingBox[i].y + sin(m_orientation)*m_boundingBox[i].x;

		//translation
		x += m_position.x;
		y += m_position.y;

		m_obb[i].x = x;
		m_obb[i].y = y;
	}

	return m_obb;


}